/*site app*/
jQuery(function($){
	/*home setting height*/
	var articleSetHeightApp = {
		isSetAbooutWidth:false,
		getBannerW: function(element){
			/*设计时的尺寸*/
			var base = [1280,352];
			var baseWidth = 1920;
			var winW = $(window).width();
			var k = winW/baseWidth;
			/*width根据样式g-80里面的79%而来*/			
			var aboutW = $(window).width()*0.79;
			var aboutLW = $(element).find('.about-jd-l').data('width');
			var aboutRW = $(element).find('.about-jd-r').data('width');
			var $aboutJdL = $(element).find('.about-jd-l');
			var $aboutJdR = $(element).find('.about-jd-r');
			if(aboutW < 600){
				aboutW = 600;
			}
			$aboutJdL.width(Math.floor((aboutW/base[0])*aboutLW));
			$aboutJdL.find('img').width(Math.floor((aboutW/base[0])*aboutLW));
			$(element).height($aboutJdL.height()).width(aboutW);
			$aboutJdR.width(Math.floor((aboutW/base[0])*aboutRW));
			
			/*go png width default 180*/
			var goW = 180*k;
			if(goW < 100){
				goW = 100;
			}
			$('.J-about-jd-go-item').find('img').width(goW);
			
			/*about vip img width default 344*/
			var vipW = 344*k*1.3;
			if(vipW < 245 ){
				vipW = 245;
			}
			$('.J-about-vip-img').width(vipW);
		},
		setArticle: function(winH){
			var that = this;						
			/*var aboutH = $('.J-about-banner').find('.about-banner-img').height()-4;
			$('.J-about-wrap').css({'top':aboutH});*/
			/*about banner调用*/
			that.getBannerW('.J-aobut-list0');
			that.getBannerW('.J-aobut-list1');			
		},
		init: function(){
			var that = this;
			var winH = $(window).height()-120;
			that.setArticle(winH);
			$(window).on('resize',function(){
				setTimeout(function (){
					var tempH = $(window).height()-120;					
					that.setArticle(tempH);
				},30);
			});
			
			/*about banner dialog调用*/	
			dialogSlider('.J-about-visual0','.J-about-image0',true);
			dialogSlider('.J-about-visual1','.J-about-image1',true);
			
			$('.J-aobut-list0').find('.J-about-jd-go-item').on('click',function (){
				var id = $(this).data('id');
				$('.J-aobut-list0').find('.J-about-image0').find('li').each(function() {
					dialogImg(this,id);
				});
			});
			
			$('.J-aobut-list1').find('.J-about-jd-go-item').on('click',function (){
				var id = $(this).data('id');
				$('.J-aobut-list1').find('.J-about-image1').find('li').each(function() {
					dialogImg(this,id);
				});
			});
			
			function dialogImg(obj,id){
				if(!$(obj).position().left){
					var $img = $(obj).find('img');
					var img = new Image();
					img.src = $img.attr('src');
					var w = img.width;
					var h = img.height;
					aboutDialog(w,h,id);
				}
			}
		}
	};
	articleSetHeightApp.init();
	
	/*about 弹框*/
	function aboutDialog(w,h,id){		
		var dialogH = h;
		var dialogW = w;
		$('.J-dialog-details').find('.dialog-details').css({'width':dialogW,'height':dialogH});	
		var Touchable = Modernizr.touch || window.navigator.userAgent.indexOf("Touch") != -1;
		if(Touchable){
			$('.J-dialog-details-close').css({"top":-60,"right":"25px"});
			$('.J-dialog-details').find('.dialog-details').css({"padding-right":"10px"});
		}
		var pagei = $.layer({
			type:1,
			border: [0],
			area: [dialogW, dialogH],  
			title: false,
			shade : [1 , '#646464' , true],
			closeBtn: false,
			offset:[
			(function(){
				var winH = $(window).height();
				var temp = (winH - parseInt(dialogH,10))/2;
				if(temp < 0) {
					temp = 0;
				}
				return temp;
			})()
			,'50%'],
			page: {dom: '.J-dialog-details'},
			success: function(){
				var page = $('.J-dialog-details-close');
				page.on('click', function(){
					layer.close(pagei);
					$('.J-dialog-about').html("");
				});
				/*取模板中的数据*/
				$('.J-template').each(function() {
                    if($(this).data('id')==id){
						$('.J-dialog-about').html($(this).html());
						/*注意是从J-dialog-about里面取*/
						dialogSlider('.J-dialog-about .J-about-visual001','.J-about-image001',true);
					}
                });	
			}
		});	
	}
});

